package com.cuoyi.coupon.mall;

import cn.hutool.core.date.DatePattern;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.TemplateType;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Mybatis Plus Generator
 *
 * @author v_tanhanlin@saicmotor.com
 */
public class MybatisPlusGenerator {

    /**
     * 仅需修改如下配置
     */
    private final static String parentPackage = "com.cuoyi.coupon.mall.mybatis";
    private final static String jdbcUrl = "jdbc:mysql://139.198.181.96:3306/coupon_mall_dev";
    private final static String username = "root";
    private final static String password = "13919818196";
    private final static List<String> tables = Arrays.asList(
            "dictionary"
            );


    /**
     * mybatis自动生成不会直接覆盖项目中的class
     * 代码生成器代码生成到 ${user.dir}/generator ,请根据需要复制到项目中
     */
    public static void mybatisGenerate(){

        String projectPath = System.getProperty("user.dir")+"/generator";
        String classOutputDir = projectPath + "/src/main/java";
        String mapperXmlOutputDir = projectPath + "/src/main/resources/mybatis/mapper";

        FastAutoGenerator.create(jdbcUrl, username, password)
                .globalConfig(builder -> builder.author("Mybatis Plus Generator")
                        .fileOverride().dateType(DateType.TIME_PACK)
                        .commentDate(DatePattern.NORM_DATETIME_PATTERN).outputDir(classOutputDir))
                .packageConfig(builder -> builder.parent(parentPackage)
                        .pathInfo(Collections.singletonMap(OutputFile.mapperXml, mapperXmlOutputDir)))
                .templateConfig(builder -> builder.disable(TemplateType.CONTROLLER))
                .strategyConfig(builder -> builder.enableSkipView().addInclude(tables)
                        .entityBuilder().enableLombok().enableChainModel()
                        .serviceBuilder().formatServiceFileName("%sService")
                        .mapperBuilder().enableBaseColumnList().enableBaseResultMap())
                .templateEngine(new VelocityTemplateEngine())
                .execute();
    }

    public static void main(String[] args) {
        mybatisGenerate();
    }

}
